<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8"/>
    <title>测试报告</title>
    <link href="assets/style.css" rel="stylesheet" type="text/css"/></head>
  <body onLoad="init()">
    <script>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */


function toArray(iter) {
    if (iter === null) {
        return null;
    }
    return Array.prototype.slice.call(iter);
}

function find(selector, elem) { // eslint-disable-line no-redeclare
    if (!elem) {
        elem = document;
    }
    return elem.querySelector(selector);
}

function find_all(selector, elem) {
    if (!elem) {
        elem = document;
    }
    return toArray(elem.querySelectorAll(selector));
}

function sort_column(elem) {
    toggle_sort_states(elem);
    const colIndex = toArray(elem.parentNode.childNodes).indexOf(elem);
    let key;
    if (elem.classList.contains('result')) {
        key = key_result;
    } else if (elem.classList.contains('links')) {
        key = key_link;
    } else {
        key = key_alpha;
    }
    sort_table(elem, key(colIndex));
}

function show_all_extras() { // eslint-disable-line no-unused-vars
    find_all('.col-result').forEach(show_extras);
}

function hide_all_extras() { // eslint-disable-line no-unused-vars
    find_all('.col-result').forEach(hide_extras);
}

function show_extras(colresult_elem) {
    const extras = colresult_elem.parentNode.nextElementSibling;
    const expandcollapse = colresult_elem.firstElementChild;
    extras.classList.remove('collapsed');
    expandcollapse.classList.remove('expander');
    expandcollapse.classList.add('collapser');
}

function hide_extras(colresult_elem) {
    const extras = colresult_elem.parentNode.nextElementSibling;
    const expandcollapse = colresult_elem.firstElementChild;
    extras.classList.add('collapsed');
    expandcollapse.classList.remove('collapser');
    expandcollapse.classList.add('expander');
}

function show_filters() {
    const filter_items = document.getElementsByClassName('filter');
    for (let i = 0; i < filter_items.length; i++)
        filter_items[i].hidden = false;
}

function add_collapse() {
    // Add links for show/hide all
    const resulttable = find('table#results-table');
    const showhideall = document.createElement('p');
    showhideall.innerHTML = '<a href="javascript:show_all_extras()">显示详情</a> / ' +
                            '<a href="javascript:hide_all_extras()">隐藏详情</a>';
    resulttable.parentElement.insertBefore(showhideall, resulttable);

    // Add show/hide link to each result
    find_all('.col-result').forEach(function(elem) {
        const collapsed = get_query_parameter('collapsed') || 'Passed';
        const extras = elem.parentNode.nextElementSibling;
        const expandcollapse = document.createElement('span');
        if (extras.classList.contains('collapsed')) {
            expandcollapse.classList.add('expander');
        } else if (collapsed.includes(elem.innerHTML)) {
            extras.classList.add('collapsed');
            expandcollapse.classList.add('expander');
        } else {
            expandcollapse.classList.add('collapser');
        }
        elem.appendChild(expandcollapse);

        elem.addEventListener('click', function(event) {
            if (event.currentTarget.parentNode.nextElementSibling.classList.contains('collapsed')) {
                show_extras(event.currentTarget);
            } else {
                hide_extras(event.currentTarget);
            }
        });
    });
}

function get_query_parameter(name) {
    const match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
    return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}

function init () { // eslint-disable-line no-unused-vars
    reset_sort_headers();

    add_collapse();

    show_filters();

    toggle_sort_states(find('.initial-sort'));

    find_all('.sortable').forEach(function(elem) {
        elem.addEventListener("click",
                              function(event) {
                                  sort_column(elem);
                              }, false)
    });
	// 修改用例报告显示的用例名称
	var case_name_td = document.getElementsByClassName("col-name");
		for(var i = 0; i < case_name_td.length; i++)
			try{
				case_name_td[i].innerText = case_name_td[i].innerText.split("\[")[1].split("\]")[0];
			}
			catch(err){
				// 如果表格中没有[]会抛异常，如果抛异常我就显示null，如果你想显示别的东西自己改吧，因为通常只要我们使用参数化就有[]显示
				case_name_td[i].innerText = "测试用例无参数数据";
			}

};

function sort_table(clicked, key_func) {
    const rows = find_all('.results-table-row');
    const reversed = !clicked.classList.contains('asc');
    const sorted_rows = sort(rows, key_func, reversed);
    /* Whole table is removed here because browsers acts much slower
     * when appending existing elements.
     */
    const thead = document.getElementById('results-table-head');
    document.getElementById('results-table').remove();
    const parent = document.createElement('table');
    parent.id = 'results-table';
    parent.appendChild(thead);
    sorted_rows.forEach(function(elem) {
        parent.appendChild(elem);
    });
    document.getElementsByTagName('BODY')[0].appendChild(parent);
}

function sort(items, key_func, reversed) {
    const sort_array = items.map(function(item, i) {
        return [key_func(item), i];
    });

    sort_array.sort(function(a, b) {
        const key_a = a[0];
        const key_b = b[0];

        if (key_a == key_b) return 0;

        if (reversed) {
            return key_a < key_b ? 1 : -1;
        } else {
            return key_a > key_b ? 1 : -1;
        }
    });

    return sort_array.map(function(item) {
        const index = item[1];
        return items[index];
    });
}

function key_alpha(col_index) {
    return function(elem) {
        return elem.childNodes[1].childNodes[col_index].firstChild.data.toLowerCase();
    };
}

function key_link(col_index) {
    return function(elem) {
        const dataCell = elem.childNodes[1].childNodes[col_index].firstChild;
        return dataCell == null ? '' : dataCell.innerText.toLowerCase();
    };
}

function key_result(col_index) {
    return function(elem) {
        const strings = ['Error', 'Failed', 'Rerun', 'XFailed', 'XPassed',
            'Skipped', 'Passed'];
        return strings.indexOf(elem.childNodes[1].childNodes[col_index].firstChild.data);
    };
}

function reset_sort_headers() {
    find_all('.sort-icon').forEach(function(elem) {
        elem.parentNode.removeChild(elem);
    });
    find_all('.sortable').forEach(function(elem) {
        const icon = document.createElement('div');
        icon.className = 'sort-icon';
        icon.textContent = 'vvv';
        elem.insertBefore(icon, elem.firstChild);
        elem.classList.remove('desc', 'active');
        elem.classList.add('asc', 'inactive');
    });
}

function toggle_sort_states(elem) {
    //if active, toggle between asc and desc
    if (elem.classList.contains('active')) {
        elem.classList.toggle('asc');
        elem.classList.toggle('desc');
    }

    //if inactive, reset all other functions and add ascending active
    if (elem.classList.contains('inactive')) {
        reset_sort_headers();
        elem.classList.remove('inactive');
        elem.classList.add('active');
    }
}

function is_all_rows_hidden(value) {
    return value.hidden == false;
}

function filter_table(elem) { // eslint-disable-line no-unused-vars
    const outcome_att = 'data-test-result';
    const outcome = elem.getAttribute(outcome_att);
    const class_outcome = outcome + ' results-table-row';
    const outcome_rows = document.getElementsByClassName(class_outcome);

    for(let i = 0; i < outcome_rows.length; i++){
        outcome_rows[i].hidden = !elem.checked;
    }

    const rows = find_all('.results-table-row').filter(is_all_rows_hidden);
    const all_rows_hidden = rows.length == 0 ? true : false;
    const not_found_message = document.getElementById('not-found-message');
    not_found_message.hidden = !all_rows_hidden;
}
</script>
    <h1>自定义接口测试报告名称</h1>
    <p>生成报告时间：2021-09-27 14:51:42</p>
    <h2>测试环境</h2>
    <table id="environment">
      <tr>
        <td>JAVA_HOME</td>
        <td>C:\Program Files (x86)\Java\jdk1.6.0</td></tr>
      <tr>
        <td>Python版本</td>
        <td>3.9.0</td></tr>
      <tr>
        <td>包</td>
        <td>Requests(2.24.0)，PyMySQL(1.0.2)，Pandas(1.3.3)，Pytest(6.2.5)，Pytest-html(3.1.1)</td></tr>
      <tr>
        <td>平台</td>
        <td>Windows-10-10.0.19041-SP0</td></tr>
      <tr>
        <td>项目名称</td>
        <td>自定义项目名称</td></tr></table>
    <h2>用例统计</h2>
    <p>执行了3个测试，耗时0.36秒</p>
    <p class="filter" hidden="true">(取消)勾选复选框, 以便筛选测试结果</p><input checked="true" class="filter" data-test-result="passed" hidden="true" name="filter_checkbox" onChange="filter_table(this)" type="checkbox"/><span class="passed">1 通过</span>, <input checked="true" class="filter" data-test-result="skipped" disabled="true" hidden="true" name="filter_checkbox" onChange="filter_table(this)" type="checkbox"/><span class="skipped">0 跳过</span>, <input checked="true" class="filter" data-test-result="failed" hidden="true" name="filter_checkbox" onChange="filter_table(this)" type="checkbox"/><span class="failed">2 失败</span>, <input checked="true" class="filter" data-test-result="error" disabled="true" hidden="true" name="filter_checkbox" onChange="filter_table(this)" type="checkbox"/><span class="error">0 错误</span>, <input checked="true" class="filter" data-test-result="xfailed" disabled="true" hidden="true" name="filter_checkbox" onChange="filter_table(this)" type="checkbox"/><span class="xfailed">0 预期失败</span>, <input checked="true" class="filter" data-test-result="xpassed" disabled="true" hidden="true" name="filter_checkbox" onChange="filter_table(this)" type="checkbox"/><span class="xpassed">0 预期通过</span>
    <h2>测试结果</h2>
    <table id="results-table">
      <thead id="results-table-head">
        <tr>
          <th class="sortable result initial-sort" col="result">通过/失败</th>
          <th>测试描述</th>
          <th class="sortable" col="name">测试用例</th>
          <th class="sortable" col="duration">持续时间</th></tr>
        <tr hidden="true" id="not-found-message">
          <th colspan="4">无测试结果, 试着选择其他测试结果条件</th></tr></thead>
      <tbody class="failed results-table-row">
        <tr>
          <td class="col-result">Failed</td>
          <td>None</td>
          <td class="col-name">ceshi_calc4.py::test_sub[1-2--1]</td>
          <td class="col-duration">0.00</td></tr>
        <tr>
          <td class="extra" colspan="4">
            <div class="log">ceshi_calc4.py:15: in test_sub<br/>    assert actual == expect  # 断言失败时，会抛出异常（报错）<br/><span class="error">E   AssertionError: assert 3 == -1</span><br/><span class="error">E     +3</span><br/><span class="error">E     --1</span><br/><br/>During handling of the above exception, another exception occurred:<br/>ceshi_calc4.py:19: in test_sub<br/>    raise AssertionError   #抛出断言异常,不能省略<br/><span class="error">E   AssertionError</span><br/> -------------------------------Captured log call-------------------------------- <br/>2021-09-27 14:51:42 [WARNING] 1,2,-1==测试失败==实际：3 [ceshi_calc4.py:18]<br/></div></td></tr></tbody>
      <tbody class="failed results-table-row">
        <tr>
          <td class="col-result">Failed</td>
          <td>None</td>
          <td class="col-name">ceshi_calc4.py::test_sub[2-1-1]</td>
          <td class="col-duration">0.00</td></tr>
        <tr>
          <td class="extra" colspan="4">
            <div class="log">ceshi_calc4.py:15: in test_sub<br/>    assert actual == expect  # 断言失败时，会抛出异常（报错）<br/><span class="error">E   AssertionError: assert 3 == 1</span><br/><span class="error">E     +3</span><br/><span class="error">E     -1</span><br/><br/>During handling of the above exception, another exception occurred:<br/>ceshi_calc4.py:19: in test_sub<br/>    raise AssertionError   #抛出断言异常,不能省略<br/><span class="error">E   AssertionError</span><br/> -------------------------------Captured log call-------------------------------- <br/>2021-09-27 14:51:42 [WARNING] 2,1,1==测试失败==实际：3 [ceshi_calc4.py:18]<br/></div></td></tr></tbody>
      <tbody class="passed results-table-row">
        <tr>
          <td class="col-result">Passed</td>
          <td>None</td>
          <td class="col-name">ceshi_calc4.py::test_sub[1-0-1]</td>
          <td class="col-duration">0.00</td></tr>
        <tr>
          <td class="extra" colspan="4">
            <div class="log"> -------------------------------Captured log call-------------------------------- <br/>2021-09-27 14:51:42 [INFO] 1,0,1==测试通过 [ceshi_calc4.py:16]<br/></div></td></tr></tbody></table></body></html>